package com.filmbooks.activity.zhihu;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;

import com.bumptech.glide.Glide;
import com.filmbooks.R;
import com.filmbooks.base.BaseWebViewLoadActivity;
import com.filmbooks.constant.BundleKeyConstant;
import com.filmbooks.contract.detail.ZhihuDetailContract;
import com.filmbooks.model.home.bean.home.ZhihuDailyDetailBean;
import com.filmbooks.presenter.detail.ZhihuDeatilPresenter;
import com.orhanobut.logger.Logger;
import com.zyw.horrarndoo.sdk.base.BasePresenter;
import com.zyw.horrarndoo.sdk.utils.HtmlUtils;
import com.zyw.horrarndoo.sdk.utils.ResourcesUtils;

/**
 * Created by heshuxiang on 2018/3/6.
 * 描述：
 * 公司：盟将威
 * 作者：heshuxiang
 * 日期：2018/3/6.
 * 工程：FilmBooks
 * 包：com.filmbooks.activity.zhihu
 */

public class ZhihuDailyDetailActivity extends BaseWebViewLoadActivity<ZhihuDetailContract.ZhihuDetailPresenter, ZhihuDetailContract.IZhihuDetailModel> implements ZhihuDetailContract.IZhihuDetailView {
    @NonNull
    @Override
    public BasePresenter initPresenter() {
        return ZhihuDeatilPresenter.newInstance();
    }

    @Override
    protected void loadDetail() {
        mPresenter.loadDailyDetail(mId);

    }

    @Override
    protected void initData() {
        super.initData();
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            mId = bundle.getString(BundleKeyConstant.ARG_KEY_ZHIHU_DETAIL_ID);
            mTitle = bundle.getString(BundleKeyConstant.ARG_KEY_ZHIHU_DETAIL_TITLE);
        }
    }

    private String mId, mTitle;

    @Override
    protected String getToolbarTitle() {
        return ResourcesUtils.getString(R.string.zhihu_detail_title);
    }

    @Override
    public void showDailyDetail(ZhihuDailyDetailBean bean) {
        flNetView.setVisibility(View.GONE);
        Glide.with(mContext).load(bean.getImage()).crossFade().into(ivDetail);
        tvDetailTitle.setText(bean.getTitle());
        tvDetailCopyright.setText(bean.getImage_source());
        String htmlData = HtmlUtils.createHtmlData(bean.getBody(), bean.getCss(), bean.getJs());
        nswvDetailContent.loadData(htmlData, HtmlUtils.MIME_TYPE, HtmlUtils.ENCODING);
    }

    @Override
    public void showNetworkError() {
        Logger.e("Network error.");
        vNetworkError.setVisibility(View.VISIBLE);
    }


    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        tvDetailTitle.setText(mTitle);
    }
}
